package day0605

/**
  * @program: hadoop
  * @description: map与flatMap
  * @author: Qiang.Ye
  * @date: 2019-06-08 06:30
  **/
object Demo1 {


  def flatMap1():Unit = {
    val li = List(1,2,3)
    val result = li.flatMap(x=> x match {
      case 3 => List('a','b')
      case _ => List(x*2)
    })
    println(result)
  }


  def  map1(): Unit ={
    val li = List(1,2,3)
    val res = li.map(x=> x match {
      case 3 => List('a','b')
      case _ => (x*2)
    })
    println(res)
  }


  /**
    *map1的执行分析
    * 1     2       Listt(2,2,3)
    * 2     4       Listt(2,4,3)
    * 3     List('a','b')       Listt(2,2,List('a','b'))
    *
    * flatMap执行分析
    * 1. List(1*2)    List(2)
    * 2. List(2*2)    List(4)
    * 3. List('a','b')
    *
    * @param args
    */
  def main(args: Array[String]): Unit = {
    map1()
//    flatMap1();
  }


}
